import pandas as pd

# df = pd.DataFrame({'ID':[1,2,3],'Name':['Tom','Amy','Jack']})
# df = df.set_index('ID')
# df.to_excel('D:/ITaudit/pandas_excel/Mytest1.xlsx')
# print('Done')
# people = pd.read_excel('D:/ITaudit/pandas_excel/people_copy.xlsx')

# print(people.tail())
# print(people.shape)

# print(f'行列总计数：{people.shape}')
#没有主键header情况处理情形：people = pd.read_excel('D:/ITaudit/pandas_excel/people_copy.xlsx',header = NOne)

# people.columns = ['ID','Type','Title','Firstname','Middlename','Latname']
# # people = people.set_index('ID')
# people.set_index('ID',inplace=True)
# # print(f'列名：{people.columns}')
# people.to_excel('D:/ITaudit/pandas_excel/people1.xlsx')
# print('done')
# people1 = pd.read_excel('D:/ITaudit/pandas_excel/people1.xlsx')
# people1.to_excel('D:/ITaudit/pandas_excel/people2.xlsx')

# print(people1.head(3))
# people2 = pd.read_excel('D:/ITaudit/pandas_excel/people2.xlsx',index_col = 'ID')
# people2.to_excel('D:/ITaudit/pandas_excel/people3.xlsx')
# print('done')
# 方法一：
# d ={'x':10,'y':20,'z':30}
# s1 = pd.Series(d)
# print(s1)
# # 方法二：
# L1 = [100,200,300]
# L2= ['x','y','z']
# s1 = pd.Series(L1,index=L2)
# # print(s1)
# 方法三：(最常用)
s1 = pd.Series([100,200,300],index=[1,2,3],name='A')
# print(s1)
s2 = pd.Series([10,20,30],index=[1,2,3],name='B')
s3 = pd.Series([1,2,3],index=[1,2,3],name='C')
df = pd.DataFrame({s1.name:s1,s2.name:s2,s3.name:s3})
print(df)
print('-----------------------')
#df提取行数据
print(df.loc[[1,2]])#提取多行数据  第一行和第二行
print(df.iloc[[0,1]]) #提取多行数据  第一行和第二行

print(df.loc[0:3])#切片，提取多行连续数据  第一行到第三行
# df列数据
print(df['A'])   #提取一列数据
print(df[['A','B']])#提取多列数据
print(df.loc[:,['A','B']])#逗号左侧表示行，右侧表示列,提取数学和英语所有行成绩
#提取区域数据
print(df.loc[[1,2],['A','B']]) #1行A数据，2行B数据
# 提取指定条件数据
print(df.loc[df['A']>=200])#单一条件：提取A列大于200的所有数据
# print(df.loc([df['A']>=200]) & ([df['B']>=20]))#多个条件用运算符

